package com.example.seakdreamandroid.accountInfo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.seakdreamandroid.R;

/**
 * 何鸿辉
 * 昵称修改界面
 */
public class InfoEditActivity extends AppCompatActivity {
    //控件
    private ImageView imgReturn;
    private EditText edit;
    private TextView title;
    private Button btnSave;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info_edit);
        getView();
        initView();
        setListener();
    }

    private void initView() {
        Intent intent = getIntent();
        int requestCode = intent.getIntExtra("requestCode",0);
        String info = intent.getStringExtra("info");
        switch(requestCode){
            case AccountInfoActivity.EDIT_NICKNAME_REQUEST_CODE:
                title.setText("昵称修改");
                edit.setHint("昵称");
                edit.setMaxWidth(32);
                edit.setInputType(InputType.TYPE_CLASS_TEXT);
                break;
            case AccountInfoActivity.EDIT_LOCATION_REQUEST_CODE:
                title.setText("地址修改");
                edit.setHint("地址");
                edit.setMaxWidth(120);
                edit.setInputType(InputType.TYPE_CLASS_TEXT);
                break;
        }
        edit.setText(info);
    }

    private void getView(){
        imgReturn = findViewById(R.id.img_return);
        title = findViewById(R.id.title);
        edit = findViewById(R.id.edit);
        btnSave = findViewById(R.id.btn_save);
    }

    private void setListener(){
        imgReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InfoEditActivity.this.finish();
            }
        });
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("info",edit.getText().toString());
                setResult(RESULT_OK,intent);
                finish();
            }
        });
    }
}